package com.lagou.edu.utils;

import com.lagou.edu.annotation.Autowired;
import com.lagou.edu.annotation.Service;

/**
 * 事务管理器类：负责手动事务的开启、提交、回滚
 */
@Service
public class TransactionManager {

    @Autowired
    private ConnectionUtils connectionUtils;

    public void setConnectionUtils(ConnectionUtils connectionUtils) {
        this.connectionUtils = connectionUtils;
    }

    //开启手动事务控制
    public void beginTransaction() throws Exception{
        connectionUtils.getCurrentThreadConn().setAutoCommit(false);
    }
    //提交事务
    public void commit()throws Exception{
        connectionUtils.getCurrentThreadConn().commit();

    }
    //回滚事务
    public void rollback()throws Exception{
        connectionUtils.getCurrentThreadConn().rollback();

    }
}
